#include "net.h"

int net_init(int *Servfd)
{
	*Servfd = socket(AF_INET,SOCK_STREAM,0);
    if(*Servfd<0) 
    {
        perror("socket faile:");
        return -1;
    }
    //printf("socket ok\n");
    //bind
    struct sockaddr_in servaddr;
    //bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(6666);
    servaddr.sin_addr.s_addr = inet_addr("192.168.1.207");
    int ret = bind(*Servfd,(struct sockaddr*)&servaddr,sizeof(servaddr));
    if(ret<0)
    {
        perror("bind faile:");
        return -1;
    }
    //printf("bind success\n");
    //listen
    ret = listen(*Servfd,10);
    if(ret<0)
    {
        perror("listen faile:");
        return -1;
    }
    //printf("listening.......\n");
	return 0;
}

int udp_init(int *udpSfd)
{
    *udpSfd = socket(AF_INET,SOCK_DGRAM,0);
    if(*udpSfd<0)
    {
        perror("socket error");
        return -1;
    }
    //printf("socket success\n");
    return 0;   
}
